package com.tarena.spring.boot;

import com.tarena.spring.boot.bean.Bean01;
import com.tarena.spring.boot.config.Demo01Config;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.lang.annotation.Target;

public class RunSpring {
    /**
     * 加载xml创建spring容器
     * 获取spring上下文
     */
    @Test
    public void xmlLoad(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("demo01.xml");
        //获取bean对象
        Bean01 bean = context.getBean(Bean01.class);// 获取一个容器的bean对象
        // 返回一个bean对象 如果有两个 则抛出异常·
        bean.identity();

    }
    /**
     * 加载配置类 启动spring容器
     */
    @Test
    public void configLoad(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Demo01Config.class);
        Bean01 bean01 = context.getBean(Bean01.class);
        bean01.identity();
    }

}
